package com.mall.util

/**
 * 统一API响应结果封装
 */
data class ResponseUtil<T>(
    val code: Int,
    val message: String,
    val data: T?
) {
    companion object {
        /**
         * 成功返回结果
         */
        fun <T> success(data: T): ResponseUtil<T> {
            return ResponseUtil(200, "操作成功", data)
        }

        /**
         * 成功返回结果
         */
        fun <T> success(message: String, data: T): ResponseUtil<T> {
            return ResponseUtil(200, message, data)
        }

        /**
         * 失败返回结果
         */
        fun <T> errorWithCode(code: Int, message: String): ResponseUtil<T> {
            return ResponseUtil(code, message, null)
        }

        /**
         * 失败返回结果
         */
        fun <T> error(message: String): ResponseUtil<T> {
            return ResponseUtil(500, message, null)
        }
    }
}